package servlets;

import entities.Admin;
import entities.User;
import java.io.IOException;
import javax.inject.Inject;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import sessions.IUserAccountSession;

/**
 * Trabalho PD - 2014/2015
 *
 * @author a21210380 a21210392
 */
@WebServlet("/homepage/navbar")
public class NavbarServlet extends HttpServlet {

    private @Inject
    IUserAccountSession userAccountSession;

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        if (!userAccountSession.isVisitor()) {
            Admin admin = userAccountSession.getAdmin();
            if (admin != null) {
                req.setAttribute("admin", admin);
            }
            User user = userAccountSession.getUser();
            if (user != null) {
                req.setAttribute("user", user);
            } else {
                req.setAttribute("cancelled", userAccountSession.isCancelled());
                req.setAttribute("waiting", userAccountSession.isWaitingAdminReview());
            }
        }
        getServletConfig().getServletContext().getRequestDispatcher(ServletBase.JSP_NAVBAR).forward(req, resp);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        getServletConfig().getServletContext().getRequestDispatcher(ServletBase.JSP_NAVBAR).forward(req, resp);
    }

}
